package bandidong.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "tbl_category", catalog = "web_ban_di_dong_db", schema = "")
@XmlRootElement
public class Category implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "category_id", nullable = false)
    private Integer categoryId;
    
    @NotNull
    @Size(min = 1, max = 500)
    @Column(name = "category_name", nullable = false, length = 500)
    private String categoryName;
    
    @Size(max = 1000)
    @Column(name = "category_description", length = 1000)
    private String categoryDescription;
    
    @OneToMany(mappedBy = "category", fetch = FetchType.EAGER)
    private Set<Mobile> mobileSet = new HashSet<Mobile>();

    public Category() {
    }

    public Category(Integer categoryId, String categoryName, String categoryDescription) {
        this.categoryId = categoryId;
        this.categoryName = categoryName;
        this.categoryDescription = categoryDescription;
    }
    
    public Category(Integer categoryId, String categoryName, String categoryDescription, 
            Set<Mobile> mobileSet) {
        this(categoryId, categoryName, categoryDescription);
        this.mobileSet = mobileSet;
    }

    public Integer getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public String getCategoryDescription() {
        return categoryDescription;
    }

    public void setCategoryDescription(String categoryDescription) {
        this.categoryDescription = categoryDescription;
    }

    public Set<Mobile> getMobileSet() {
        return mobileSet;
    }

    public void setMobileSet(Set<Mobile> mobileSet) {
        this.mobileSet = mobileSet;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (categoryId != null ? categoryId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Category)) {
            return false;
        }
        Category other = (Category) object;
        if ((this.categoryId == null && other.categoryId != null) || (this.categoryId != null && !this.categoryId.equals(other.categoryId))) {
            return false;
        }
        return true;
    }
}
